package com.ruoyi.web.controller.obs;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.vo.ObsUploadRespVo;
import com.ruoyi.common.utils.obs.ObsUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Api(value = "OBS控制器", tags = {"OBS管理"})
@AllArgsConstructor
@RestController
@RequestMapping("/obs")
public class ObsController {

    private final ObsUtils obsUtils;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public AjaxResult<ObsUploadRespVo> upload(@RequestParam(value="file") MultipartFile file) throws IOException {
        return AjaxResult.success(obsUtils.uploadMultipartFile(file));
    }

    @ApiOperation("文件下载")
    @PostMapping("/download")
    public void download(@RequestParam("objectKey") String objectKey){
        obsUtils.downFile(objectKey);
    }

    @ApiOperation("删除文件")
    @PostMapping("/delFile")
    public AjaxResult delFile(@RequestParam("objectKey") String objectKey) {
        obsUtils.deleteFile(objectKey);
        return AjaxResult.success();
    }
}
